package com.bop.dehong.webview;

import android.content.ComponentName;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;

import com.base.dehong.util.LogUtils;
import com.bop.dehong.R;
import com.bop.dehong.base.TopManager;
import com.bop.dehong.base.WebActivityBaseFrame;
import com.bop.dehong.config.Config;
import com.bop.dehong.main.MainActivity;

/**
 * @author TangWenhan/YeFengyun
 *2015-11-16下午3:10:28
 */
public class WebViewActivity extends WebActivityBaseFrame{
	private TopManager manager;
	private boolean goBack = false;
	public static int RESULT_FOR_RECHARGE = 100;
	
	@Override
	protected void initTop() {
		goBack = getIntent().getBooleanExtra(Config.GO_BACK, false);
		View mView = getView(R.id.top);
		manager = new TopManager(mView);
		manager.setLeftImageVisibility(View.VISIBLE);
	}

	@Override
	protected void initData() {
		String titleStr = getIntent().getStringExtra("title");
		manager.setTitle(titleStr);
		String urlStr = getIntent().getStringExtra("url");
		LogUtils.e("请求weburl==" + urlStr);
		loadUrl(urlStr);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode != RESULT_OK) {
			return;
		}
		if (requestCode == RESULT_FOR_RECHARGE) {
			Intent intent = new Intent(this,MainActivity.class);
			intent.putExtra("page", 3);
			startActivity(intent);
		}
	}
	
	@Override
	protected int getContentViewId() {
		TAG = getClass().getName();
		return R.layout.act_webview;
	}

	@Override
	public void setTitle(String title) {
		manager.setTitle(title);
	}

	
	@Override
	public void onTitleLeftClick(View v) {
		if (!goBack) {
			Intent  intent = new Intent(Intent.ACTION_MAIN);
			intent.addCategory(Intent.CATEGORY_LAUNCHER);
			intent.setComponent(new ComponentName(this.getPackageName(), 
			this.getPackageName() + ".main." + "MainActivity"));
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| 
			Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);//关键的一步，设置启动模式
			startActivity(intent);
		}else {
			super.onTitleLeftClick(v);
		}
			
	}

	@Override
	public void onClick(View v)
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id)
	{
		// TODO Auto-generated method stub
		
	}
	
}

